package com.ityuwen.mengyagushi.order.api;

import com.ityuwen.mengyagushi.common.login.GuiGuLogin;
import com.ityuwen.mengyagushi.common.result.Result;
import com.ityuwen.mengyagushi.model.order.OrderInfo;
import com.ityuwen.mengyagushi.order.service.OrderInfoService;
import com.ityuwen.mengyagushi.vo.order.OrderInfoVo;
import com.ityuwen.mengyagushi.vo.order.TradeVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order/orderInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;

	@GuiGuLogin
	@PostMapping("trade")
	public Result<OrderInfoVo> trade(@RequestBody TradeVo tradeVo){
		OrderInfoVo orderInfoVo = this.orderInfoService.trade(tradeVo);
		return Result.ok(orderInfoVo);
	}

	@GuiGuLogin
	@PostMapping("submitOrder")
	public Result<Map<String, Object>> submitOrder(@RequestBody OrderInfoVo orderInfoVo){
		this.orderInfoService.submitOrder(orderInfoVo);
		String tradeNo = orderInfoVo.getTradeNo();
		Map<String, Object> map = new HashMap<>();
		map.put("orderNo", tradeNo);
		return Result.ok(map);
	}

	@GetMapping("getOrderInfo/{orderNo}")
	public Result<OrderInfo> getOrderInfo(@PathVariable("orderNo")String orderNo){
		OrderInfo orderInfo = this.orderInfoService.getOrderInfo(orderNo);
		return Result.ok(orderInfo);
	}

	@GuiGuLogin
	@GetMapping("findUserPage/{page}/{limit}")
	public Result<Page<OrderInfo>> findOrderInfoPage(@PathVariable("page")Integer page, @PathVariable("limit")Integer limit){
		Page<OrderInfo> orderInfoPage = this.orderInfoService.findOrderInfoPage(page, limit);
		return Result.ok(orderInfoPage);
	}
}

